﻿
CREATE PROCEDURE [svc].[GetCountOfAllServersOverMaximumByType]
(
	@FromDate				datetime,
	@ToDate					datetime, 
	@Limit					int, 
	@Type					VARCHAR(20)
)
AS
BEGIN

IF @Type = 'CpuTime' 
BEGIN 
	SELECT COUNT(*) FROM dbo.ExecSessionLog 
	WHERE LastModifiedDate BETWEEN @FromDate AND @ToDate 
	AND CpuTime > @Limit 
END

IF @Type = 'Reads' 
BEGIN 
	SELECT COUNT(*) FROM dbo.ExecSessionLog 
	WHERE LastModifiedDate BETWEEN @FromDate AND @ToDate 
	AND Reads > @Limit 
END

IF @Type = 'Writes' 
BEGIN 
	SELECT COUNT(*) FROM dbo.ExecSessionLog 
	WHERE LastModifiedDate BETWEEN @FromDate AND @ToDate 
	AND Writes > @Limit 
END

IF @Type = 'WaitTime' 
BEGIN 
	SELECT COUNT(*) FROM dbo.ExecSessionLog 
	WHERE LastModifiedDate BETWEEN @FromDate AND @ToDate 
	AND WaitTime > @Limit 
END

END